package net.randomice.emf.observables.demo.extlibrary.persons.observables;

import net.randomice.emf.observables.demo.extlibrary.ExtlibraryPackage;
import net.randomice.emf.observables.demo.extlibrary.items.Book;
import net.randomice.emf.observables.demo.extlibrary.items.observables.BookOL;
import net.randomice.emf.observables.demo.extlibrary.persons.PersonsFactory;
import net.randomice.emf.observables.demo.extlibrary.persons.PersonsPackage;
import net.randomice.emf.observables.demo.extlibrary.persons.Writer;
import net.randomice.emf.observables.runtime.IObservableAbstractListObject;
import net.randomice.emf.observables.runtime.IObservableObject;
import org.eclipse.core.databinding.observable.Observables;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable object wrapper for {@link Writer}
 * @generated
 */
public class WriterOO implements IObservableObject<Writer> {
	// root object stuff

	public final static Creator<Writer, WriterOO> CREATOR = new Creator<Writer, WriterOO>() {
		public WriterOO createRoot(Writer object) {
			return new WriterOO(Observables.constantObservableValue(object,
					Writer.class));
		}

		public WriterOO createRoot() {
			return createRoot(PersonsFactory.eINSTANCE.createWriter());
		}
	};

	public static WriterOO createRoot(Writer object) {
		return CREATOR.createRoot(object);
	}

	public static WriterOO createRoot() {
		return CREATOR.createRoot();
	}

	// instance stuff	

	public final IObservableValue o;
	public final IObservableValue getObservable() {
		return o;
	}

	public WriterOO(IObservableValue observableValue) {
		Object type = observableValue.getValueType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Writer.class.equals(type));
		o = observableValue;
	}

	public Writer getValue() {
		return (Writer) o.getValue();
	}

	public void setValue(Writer newValue) {
		o.setValue(newValue);
	}

	// generic feature getters

	public IObservableValue getValueFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS.equals(feature)) {
			return getAddress();
		}
		if (PersonsPackage.Literals.PERSON__FIRST_NAME.equals(feature)) {
			return getFirstName();
		}
		if (PersonsPackage.Literals.PERSON__LAST_NAME.equals(feature)) {
			return getLastName();
		}
		if (PersonsPackage.Literals.WRITER__NAME.equals(feature)) {
			return getName();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableList getListFeature(EStructuralFeature feature) {
		if (PersonsPackage.Literals.WRITER__BOOKS.equals(feature)) {
			return getBooks().o;
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableObject<?> getValueObject(EReference feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableAbstractListObject<?> getListObject(EReference feature) {
		if (PersonsPackage.Literals.WRITER__BOOKS.equals(feature)) {
			return getBooks();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Addressable

	private IObservableValue address = null;
	public IObservableValue getAddress() {
		if (null == address) {
			address = EMFObservables.observeDetailValue(o.getRealm(), o,
					ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);
		}
		return address;
	}

	public void setAddress(String value) {
		getAddress().setValue(value);
	}

	// features from type Person

	private IObservableValue firstName = null;
	public IObservableValue getFirstName() {
		if (null == firstName) {
			firstName = EMFObservables.observeDetailValue(o.getRealm(), o,
					PersonsPackage.Literals.PERSON__FIRST_NAME);
		}
		return firstName;
	}

	public void setFirstName(String value) {
		getFirstName().setValue(value);
	}

	private IObservableValue lastName = null;
	public IObservableValue getLastName() {
		if (null == lastName) {
			lastName = EMFObservables.observeDetailValue(o.getRealm(), o,
					PersonsPackage.Literals.PERSON__LAST_NAME);
		}
		return lastName;
	}

	public void setLastName(String value) {
		getLastName().setValue(value);
	}

	// features from type Writer

	private IObservableValue name = null;
	public IObservableValue getName() {
		if (null == name) {
			name = EMFObservables.observeDetailValue(o.getRealm(), o,
					PersonsPackage.Literals.WRITER__NAME);
		}
		return name;
	}

	public void setName(String value) {
		getName().setValue(value);
	}

	private BookOL books = null;
	public BookOL getBooks() {
		if (null == books) {
			books = new BookOL(EMFObservables.observeDetailList(o.getRealm(),
					o, PersonsPackage.Literals.WRITER__BOOKS));
		}
		return books;
	}

}
